
const mongonse = require('mongoose')

module.exports.add3 = async function(data){
    return await mongonse.model('articalModel').create(data)
}

module.exports.get3 = async function({currentPage,pageSize}){
     const total = await mongonse.model('articalModel').countDocuments();
     const pages = Math.ceil(total / pageSize);
    const articalData = await mongonse.model('articalModel')
     .find()
     .limit(pageSize - 0)
     .skip((currentPage - 1) * pageSize)
     return {pages,articalData}
}

module.exports.search3 = async function({searchType,searchValue,currentPage,pageSize}){
    const total = await mongonse.model('articalModel')
    .find({[searchType]:{$regex:searchValue,$options:'$i'}});
    const pages = Math.ceil(total / pageSize);
    const articalData = await mongonse.model('articalModel')
    .find({[searchType]:{$regex:searchValue,$options:'$i'}})
    .limit(pageSize - 0)
    .skip((currentPage - 1) * pageSize)
    return {pages,articalData}
}

module.exports.delete3 = async function(data){
    return await mongonse.model('articalModel').deleteOne(data)
}

module.exports.getOne3 = async function(data){
    return await mongonse.model('articalModel').find(data)
}

module.exports.updataOne3 = async function({_id,artical_title,artical_sub,artical_img}){
    return await mongonse.model('articalModel').updateOne({_id},{artical_title,artical_sub,artical_img})
}